package com.ttbj.product.webuser.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ttbj.api.dto.Page;
import com.ttbj.api.dto.webuser.WebUserDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.webuser.WebUserService;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.constant.SalesmanEnum;
import com.ttbj.core.util.DtoTransitionUtils;
import com.ttbj.webuser.bean.po.WebUser;
import com.ttbj.webuser.dao.WebUserMapper;



@Service("webUserService")
public class WebUserServiceImpl implements WebUserService{

	@Autowired
	private WebUserMapper webUserMapper;
	
	@Override
	public List<WebUserDto> findWebUserByPage(Page page, WebUserDto webUserDto) throws BusinessException {
		if (null == webUserDto) {
			throw new BusinessException("数据有错误！", PlatFormErrorCode.OBJECT_DOES_NOT_EXIST.code());
		}
		//设置 是否删除的状态为：1未删除
		webUserDto.setIsDelete(SalesmanEnum.NOT_DELETE.getCode());
		WebUser webUser = (WebUser) DtoTransitionUtils.trans(WebUser.class, webUserDto);
		List<WebUser> webUserList = this.webUserMapper.queryWebUserByPage(page, webUser);
		List<WebUserDto> dtosList = new ArrayList<>();
		for (WebUser webUser2 : webUserList) {
			WebUserDto dto = (WebUserDto) DtoTransitionUtils.trans(WebUserDto.class, webUser2);
			dtosList.add(dto);
		}
		return dtosList;
	}

	@Override
	public Integer findWebUserByPageCount(WebUserDto webUserDto) throws BusinessException {
		if (null == webUserDto) {
			throw new BusinessException("数据有错误！", PlatFormErrorCode.OBJECT_DOES_NOT_EXIST.code());
		}
		//设置 是否删除的状态为：1未删除
		webUserDto.setIsDelete(SalesmanEnum.NOT_DELETE.getCode());
		WebUser webUser = (WebUser) DtoTransitionUtils.trans(WebUser.class, webUserDto);
		Integer count = this.webUserMapper.queryWebUserByPageCount(webUser);
		return count;
	}

}
